Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): allow recursive partial theme #239

Merged
merged 5 commits into from
Jun 20, 2019

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Jun 12, 2019

Summary

Issue #201

Allow partial theme object for chart Settings

You can now specify a PartialTheme to pass to the Settings component where every field in the full Theme type is recursively optional.

Before

If you wanted to change one property in a nested type lets say left margin we want to set to 0. You would need to include the default/base values of right, top and bottom margins for those to carry over, otherwise, they will be removed!

const theme: PartialTheme = {
  chartMargins: {
    left: 0,
    right: 10,
    top: 10,
    bottom: 10,
  },
};

After

You ONLY need to include the values you want, then pass that to the Settings component.

const theme: PartialTheme = {
  chartMargins: {
    left: 0,
  },
};

There is also no need to merge this PartialTheme theme using the mergeWithDefaultTheme function, although you can if you really want to 😏. This will happen automatically within the Settings. By default, it will deep-merge your PartialTheme with the LIGHT_THEME as a base. However, if you would like to set the base to be something else you can pass that as a prop.

<Chart className="story-chart-dark">
  <Settings
    theme={customPartialTheme}
    baseThemeType={BaseThemeTypes.Dark}
  />
  ...
/>

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@nickofthyme nickofthyme added enhancement New feature or request wip work in progress :styling Styling related issue labels Jun 12, 2019
src/specs/settings.tsx Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@nickofthyme

This comment has been minimized.

yarn.lock Outdated
@@ -4951,7 +4951,7 @@ deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=

[email protected]:
[email protected], deepmerge@^3.2.0:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markov00 it looks like we are already using this library through some dependency. Not sure if that matters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it's semantic-release via octokit... important thing is that we don't use it directly

The main tsconfig.json is what vscode uses to parse ts files. Adding a global type would not
available in excluded test files. Extended base tsconfig to current match current build config.
Allow recursive partial themes to be passed to the Setting component. Added RecursivePartial global
type.

Issue elastic#201
@nickofthyme nickofthyme marked this pull request as ready for review June 14, 2019 23:15
@nickofthyme nickofthyme removed the wip work in progress label Jun 14, 2019
@codecov-io
Copy link

codecov-io commented Jun 14, 2019

Codecov Report

Merging #239 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #239      +/-   ##
==========================================
- Coverage   97.75%   97.74%   -0.01%     
==========================================
  Files          36       36              
  Lines        2626     2621       -5     
  Branches      587      582       -5     
==========================================
- Hits         2567     2562       -5     
  Misses         52       52              
  Partials        7        7
Impacted Files Coverage Δ
src/specs/settings.tsx 96.34% <100%> (+0.39%) ⬆️
src/lib/utils/commons.ts 100% <100%> (ø) ⬆️
src/lib/themes/theme.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff7340a...12a451f. Read the comment docs.

src/@types/global.d.ts Outdated Show resolved Hide resolved
src/lib/themes/theme.ts Outdated Show resolved Hide resolved
yarn.lock Outdated
@@ -4951,7 +4951,7 @@ deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=

[email protected]:
[email protected], deepmerge@^3.2.0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it's semantic-release via octokit... important thing is that we don't use it directly

Moved global type to be utils. Updated storybook config with custom tsconfig file.
Copy link
Contributor

@emmacunningham emmacunningham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally and code LGTM!

definitely doesn't need to be handled in this PR but would be nice to also extend this to allow for partial style definitions for the per series custom styles.

@nickofthyme nickofthyme merged commit d8144ee into elastic:master Jun 20, 2019
@nickofthyme nickofthyme deleted the feat/partial-styles branch June 20, 2019 17:11
markov00 pushed a commit that referenced this pull request Jun 20, 2019
# [6.3.0](v6.2.0...v6.3.0) (2019-06-20)

### Features

* **theme:** allow recursive partial theme ([#239](#239)) ([d8144ee](d8144ee)), closes [#201](#201)
@markov00
Copy link
Member

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jun 20, 2019
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Issue released publicly :styling Styling related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants